/**
 * Created by guosc on 2016/11/4 0004.
 */
define([
    'require',
    'angular',
    'underscore'
], function (require, angular, _) {
    return  function ($scope, $rootScope, $routeParams, Resource, GillionMsg, RuleSerivce) {
        $scope.decisionTableId=$routeParams.tableId;
        angular.element('.engine-tab li:first').trigger('click');
        var decisionTable=Resource("/grule-manager/decision-tables/:id",{
            id:"@id"
        });

        RuleSerivce.promises().then(function () {
            $scope.decisionTable=$rootScope.currDecisionTable;
        });

        $scope.reset=function(){
            decisionTable.get({
                id:$scope.decisionTableId
            },function(resp){
                $scope.decisionTable=resp.data;
            });
        }

        $scope.save=function(){
            angular.element('form[name="DecisiontableForm"]').scope().DecisiontableForm.verify().then(function(){
                Resource("/grule-manager/decision-tables/"+$scope.decisionTable.id).update($scope.decisionTable,function(resp){
                    if(resp.success){
                        GillionMsg.alert("提示","保存成功！");
                        RuleSerivce.setCurrentDecisionTable($scope.decisionTable);
                        angular.element(document).trigger('refresh.menu');
                    }
                })
            });
        };

    }
});


